﻿@{Layout = "~/Views/Shared/_Layout.cshtml";}
<h1>All Bookings</h1>
<p class="Subtitle">This is a list of all bookings (goes back at most a year). </p>

<table class="Table" cellspacing="0">
    <tr>
        <th>Course</th>
        <th>Booker</th>
        <th>Room</th>
        <th>Time</th>
        <th></th>
    </tr>
    @{string previousCourse = "";
        foreach(var booking in ViewData.Model) {
            <tr onclick="location.href='@Href("~/Booking/Show/" + booking.ID)'" class="Clickable">
                <td style="width:110px;">
                    @if(previousCourse != booking.CourseInstance.Course.ID) {
                        previousCourse = booking.CourseInstance.Course.ID;
                        @booking.CourseInstance.Course.ID <text>( </text> @booking.CourseInstance.ID <text>)</text>
                    }
                </td>
                <td style="width:120px">
                    @booking.User.FirstName @booking.User.LastName
                </td>
                <td style="width:90px;">
                    @booking.Room.ID
                </td>
                <td style="width:190px;">
                    @if (booking.StartDate.Date == booking.EndDate.Date){
                        @booking.StartDate.ToShortDateString() <text> ( </text>
                        @booking.StartDate.ToShortTimeString() <text>-</text> 
                        @booking.EndDate.ToShortTimeString() <text> ) </text>
                    }else{
                        @booking.StartDate <text> - </text>
                        @booking.EndDate
                    }
                </td>
            </tr>
        }
    }
</table>